var index_sex = getCookie('sex'); // 选中显示什么性别

var view = new Vue({
    el: '#view',
    data: {
        imgurl: imgurl,
        ffList: [],
        notice: [], // 公告列表
    },
    methods: {
        // 跳转 查看用户详情
        goUserInfo: function (data) {
            go_userInfo(data.user_id, data.user_name, data.user_sex)
        },
        // 收藏
        sc: function (uid, index) {
            var _this = this;
            var status = _this.ffList[index].love;
            var url = status == 0 ? 'attention_user.php' : 'cancel_attention.php';
            _ajax(url, function (ret, err) {
                _log(JSON.stringify(ret))
                _log(JSON.stringify(err))
                if (ret && ret.code == 200) {
                    var msg = status == 0 ? '收藏成功' : '取消收藏成功';
                    _msg(msg);
                    _this.ffList[index].love = status == 0 ? 1 : 0;
                    pushMsg(uid);
                }
            }, {
                user_id: myuserid, //被看用户id
                to_user: uid, //我的用户id
            })
        },

        _url: function (param, url) {
            _url(param, url);
        },
        // 图片自适应
        imgCss: function (url, event) {
            var e = event.currentTarget;
            imgCss(url, function (w, h) {
                if (w < h) {
                    $(e).parent().addClass('img-w').removeClass('img-h');
                }
            })
        },
    }
})

addCity();
showCity();
isVip();
changeSex(); // 显示相反的性别
_scrollToBottom(function () {
    if (getCookie('urlIndex') != 0) return;
    if (heigutgao == 1) {
        pagenum++;
        getData(pagenum);
    }
})

// 显示城市
function showCity() {
    var index_city = getCookie('index_city') || '附近'; // 筛选要求的城市
    $('.city-name').text(index_city);
}

// 加载第一页
function getData(page) {
    var el = index_sex == '女' ? 'one2' : 'one1';
    var filter = $('.' + el + ' .active').attr('data-filter');
    filter = returnObj(filter);
    var _city = $('.city-name').text();
    _city = _city == '附近' ? undefined : _city;
    var param = {
        pagesize: pagesize,
        sex: '女',
        city: _city,
        user_id: myuserid,
        hot: 0,
        new: 0,
        vip: 0,
        is_identity_authentication: 0,
        longitude: getCookie('lon') || 113.320234,
        latitude: getCookie('lat') || 23.022241,
    }
    for (var k in filter) {
        param[k] = filter[k];
    }

    _log(JSON.stringify(param))
    var loading = page == 0 ? 1 : 0;
    _lists('around_people_list.php', page, loading, param);
    if (page == 0) {
        $('body').scrollTop(0);
    }
}

// 判断是否为vip
function isVip() {
    _ajax('is_vip.php', function (ret, err) {
        if (ret && ret.code == 200) {
            setCookie('isVip', 1); //是会员
            setCookie('gaoVip', 0); //是高级会员
        } else if (ret && ret.code == 202) {
            setCookie('isVip', 1); //是会员
            setCookie('gaoVip', 1); //是高级会员
        } else if (ret && ret.code == 201) {
            setCookie('isVip', 0); //不是会员
            setCookie('gaoVip', 0); //是高级会员
        }
    }, {
        user_id: myuserid
    })
}


// 切换性别列表 frame0
function changeSex() {
    index_sex = index_sex == '女' ? '男' : '女';
    if (index_sex == '女') {
        $('#sex .base-icon').addClass('nav-female-icon').removeClass('nav-male-icon');
        $('.one .wrap').eq(0).addClass('new-hide');
        $('.one .wrap').eq(1).removeClass('new-hide');
    } else {
        $('#sex .base-icon').addClass('nav-male-icon').removeClass('nav-female-icon');
        $('.one .wrap').eq(0).removeClass('new-hide');
        $('.one .wrap').eq(1).addClass('new-hide');
    }
    var el = index_sex == '女' ? 'one2' : 'one1';
    randomSwitchBtn(0, el);
}

// 切换筛选效果
function randomSwitchBtn(index, el) {
    $('.' + el + ' .list').eq(index).addClass('active').siblings().removeClass('active');
    getData(0);
}

// // 切换城市
function _areaSubmit(sCity) {
    var city = sCity;
    // _log(expressArea);
    $('.city-name').text(city);
    setCookie('index_city', city);
    getData(0);
}
// 增加城市
function addCity() {
    province.unshift('附近');
    city.unshift(['附近']);
    // intProvince();
}

var cityLen = 1; // 1 当前城市 4常驻城市
function _changeCity(city) {
    closeModalFrm();
    _areaSubmit(city);
}
// 修改当前城市
function _showCity() {
    $('#modal-wrap').removeClass('new-hide');
    _load('#modal-wrap', 'frame0/city');
}
// 隐藏模态框
function closeModalFrm() {
    $('#modal-wrap').addClass('new-hide');
}